using System.Collections.Generic;
using UnityEngine;

public class PrivateCarRespawnPoint : MonoBehaviour
{
	public GameObject emptyObject;

	public static PrivateCarRespawnPoint instance;

	public List<PositionCar> listCarRespawn = new List<PositionCar>();

	private void Awake()
	{
		instance = this;
	}

	public void SavePoint()
	{
		listCarRespawn.Clear();
		Transform[] componentsInChildren = GetComponentsInChildren<Transform>();
		PositionCar item = default(PositionCar);
		Transform[] array = componentsInChildren;
		foreach (Transform transform in array)
		{
			if (transform.tag.Equals("Respawn") && transform.position != Vector3.zero)
			{
				item.pos = transform.position;
				item.rot = transform.rotation;
				listCarRespawn.Add(item);
			}
		}
	}

	public void DeletePoint()
	{
		Transform[] componentsInChildren = GetComponentsInChildren<Transform>();
		Transform[] array = componentsInChildren;
		foreach (Transform transform in array)
		{
			if (transform.tag.Equals("Respawn"))
			{
				Object.DestroyImmediate(transform.gameObject);
			}
		}
	}

	public void ShowPoint()
	{
		foreach (PositionCar item in listCarRespawn)
		{
			GameObject gameObject = Object.Instantiate(emptyObject);
			gameObject.SetActive(true);
			gameObject.transform.rotation = item.rot;
			gameObject.transform.position = item.pos;
			gameObject.transform.parent = base.transform;
		}
	}

	public void PutAllPoint()
	{
		Ray ray = default(Ray);
		RaycastHit hitInfo = default(RaycastHit);
		for (int i = 0; i < listCarRespawn.Count; i++)
		{
			PositionCar value = listCarRespawn[i];
			ray.origin = value.pos;
			ray.direction = Vector3.down;
			if (Physics.Raycast(ray, out hitInfo, 10000f))
			{
				value.pos = hitInfo.point + Vector3.up * 2f;
				listCarRespawn[i] = value;
			}
		}
	}
}
